package com.dcms.admin.service.impl;

import com.dcms.admin.bean.User;
import com.dcms.admin.dao.UserMapper;
import com.dcms.admin.service.IUserService;
import com.dcms.util.ClassUtil;
import com.dcms.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * \* @name: UserServiceImpl
 * \* @author: 武佳伟丶
 * \* @date: 2018/2/11 0011
 * \* @tine: 22:37
 * \* @description: To change this template use File | Settings | File Templates.
 * \
 */
@Service
public class UserServiceImpl implements IUserService{

    @Autowired
    private UserMapper mapper;

    @Override
    public int deleteByPrimaryKey(Integer userId) {
        return mapper.deleteByPrimaryKey(userId);
    }

    @Override
    public int insertSelective(User record) {
        return mapper.insertSelective(record);
    }

    @Override
    public User selectByPrimaryKey(Integer userId) {
        return mapper.selectByPrimaryKey(userId);
    }

    @Override
    public int updateByPrimaryKeySelective(User record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public User selectByUsernameAndPwd(String username, String password) {
        Map param = new HashMap();
        param.put("username", username);
        param.put("password", password);
        return mapper.selectByUsernameAndPwd(param);
    }

    @Override
    public List<User> selectAll(String param, User record) {
        Map map = new HashMap();
        if (StringUtil.isNotEmpty(param)){
            map.put("param", StringUtil.appendPerCent(param));
        }
        map.putAll(ClassUtil.getFields(record));

        return mapper.selectAll(map);
    }

    @Override
    public int deleteBatch(Integer[] id) {
        return mapper.deleteBatch(id);
    }
}